package com.huadao.cart_ccs.common;

import android.view.View;

import com.jakewharton.rxbinding2.view.RxView;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;

public class SafeClick {

    public static void setSafeClick(final View view, final View.OnClickListener onClickListener){
        RxView.clicks(view).throttleFirst(1, TimeUnit.SECONDS).subscribeOn(AndroidSchedulers.mainThread()).subscribe(new Observer(){

            @Override
            public void onSubscribe(Disposable d) {}

            @Override
            public void onNext(Object value) {
                onClickListener.onClick(view);
            }

            @Override
            public void onError(Throwable e) {}

            @Override
            public void onComplete() {}
        });
    }
}
